package cn.bdqn.sys.vomapper;

import cn.bdqn.sys.model.Resources;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author zhouxp
 * @create 2019-07-27 17:35
 */

public interface ResourcesVoMapper {
	@Select("SELECT id,pid,cname,icon,url,isdel,ismenu_leaf isleaf FROM sys_resources WHERE isdel=0 AND ismenu=1 AND isstop=0 AND id IN(\n" +
			"\tSELECT resources_id FROM sys_role_resources WHERE role_id IN(\n" +
			"\tSELECT role_id FROM sys_user_role WHERE isdel=0 AND user_id=#{userid}))")
	List<Resources> getMenu(Integer userid);

	@Select("SELECT id,pid,cname,icon,url, isleaf,IF(rr.resources_id IS NULL,FALSE,TRUE) isdel FROM sys_resources r LEFT JOIN (SELECT resources_id FROM sys_role_resources WHERE role_id=#{roleid}) rr ON(r.id=rr.resources_id)")
	List<Resources> getRes(Integer roleid);

	@Select("SELECT perms FROM sys_resources WHERE id IN (SELECT resources_id FROM sys_role_resources WHERE role_id IN (SELECT role_id FROM sys_user_role WHERE user_id=#{userid}))")
	List<String> getPerms(Integer userid);
}
